/**
 * Created by Jackie.Chen on 2017/5/26.
 */
'use strict'

var exportTemplete = require('html!./data-explore.html');
require('./model.less');
module.exports = {
  template: exportTemplete,
  data:function(){
    return {
      dataList:[],
      modelId:localStorage.getItem('modelId'),
      modelName:localStorage.getItem('modelName'),
      userId:localStorage.getItem('userId')
    }
  },
  created:function(){
    //this.modelId = this.$route.params.modelId;
    //console.log(this.$route.params);
    this.getAllData();
  },
  beforeRouteEnter:function(to, from, next){
    if(!localStorage.getItem("userId")){
      layer.confirm('请先登陆', {
        btn: ['确定'] //按钮
      }, function(index){
        layer.close(index);
        next({ path: '/login' })
      });
    }else{
      next();
    }
  },
  methods:{
    getAllData:function(){
      var me = this;
      this.$http.get('/involvingDataController/getAllInvolvingDataList.do?eye_model_id='+me.modelId)
        .then(function(res) {
          //加动态id
          if(res.data.status === 'OK'){
            console.log(res.data.result.list);
            this.dataList = res.data.result.list;
          }else{
            layer.msg('系统繁忙，请稍后再试');
          }
        }.bind(this));
    },
    choose:function(e,b){
      console.log('===='+e.target.value+'----'+b);
      var me = this;
      this.$http.get('/involvingDataController/updateDataByMiss.do?userId='+me.userId+'&modelId='+me.modelId+'&cloumName='+b+'&dataValue='+e.target.value)
        .then(function(res) {
          //加动态id
          if(res.data.status === 'OK'){
            layer.msg(res.data.result);
          }else{
            layer.msg('系统繁忙，请稍后再试');
          }
        }.bind(this));

    },
    chooseEx:function(e){
      console.log('+++++'+e.target.value);
      var me = this;
      this.$http.get('/involvingDataController/updateDataByExtremum.do?userId='+me.userId+'&modelId='+me.modelId+'&cloumName='+b+'&dataValue='+e.target.value)
        .then(function(res) {
          //加动态id
          if(res.data.status === 'OK'){
            layer.msg(res.data.result);
          }else{
            layer.msg('系统繁忙，请稍后再试');
          }
        }.bind(this));
    },
    submit:function(){
      var me = this;
      localStorage.setItem('modelId',me.modelId);
      localStorage.setItem('modelName',me.modelName);
      me.$router.push('/product/result');
      //生成分析数据
      //this.$router.replace({ path:'/product/result', params: { modelId: me.modelId }})
    }
  }
}
